#pragma once

#include "leveldb/status.h"
#include "leveldb/slice.h"
#include "Stream.h"

class Size;

class Appender  {
public:
    Appender(Stream * stream);
    ~Appender();

	leveldb::Status open() ;

    //read the records & truncate the after offset of last_records
    leveldb::Status recover();

	leveldb::Status close();

    leveldb::Status append(const leveldb::Slice & str);

    const uint64_t nextSequenceNumber() const { return sequenceNumber_; }

private:
    leveldb::Status _append(uint64_t key, const leveldb::Slice & value) ;
    leveldb::Status skipToEnd(uint64_t & recordCount, uint64_t & offset);

private:
    Stream * stream_ = nullptr;
    uint64_t sequenceNumber_ = 0;
    bool isOpen_ = false;
    Stream::InternalAppender * appender_ = nullptr;
};
